using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace OraHRDAO
{
	///<summary>
	/// DAO Class for the JOBS table.
	///</summary>
	public class JOBS : Entity
	{
		private String _JOB_ID;
		private String _JOB_TITLE;
		private Int32 _MIN_SALARY;
		private Int32 _MAX_SALARY;
	
		///Default constructor
		public JOBS ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available CHILD tables to join with:
		///    - EMPLOYEES ( EMPLOYEES_EMP_JOB_FK )
		///    - JOB_HISTORY ( JOB_HISTORY_JHIST_JOB_FK )
        /// </summary>
        public JOBS(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}

		///Constructor for Joins with flat hierarchy
        public JOBS(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		///<summary>
		/// Property for column JOB_ID.
		///</summary>
		[IsNotNullable]
		[IsPK]
		[MaxLength(10)]
		public String JOB_ID
		{
			get
			{
				return _JOB_ID;
			}
			set
			{
				_JOB_ID = value;
			}
		}
		///<summary>
		/// Property for column JOB_TITLE.
		///</summary>
		[IsNotNullable]
		[MaxLength(35)]
		public String JOB_TITLE
		{
			get
			{
				return _JOB_TITLE;
			}
			set
			{
				_JOB_TITLE = value;
			}
		}
		///<summary>
		/// Property for column MIN_SALARY.
		///</summary>
		public Int32 MIN_SALARY
		{
			get
			{
				return _MIN_SALARY;
			}
			set
			{
				_MIN_SALARY = value;
			}
		}
		///<summary>
		/// Property for column MAX_SALARY.
		///</summary>
		public Int32 MAX_SALARY
		{
			get
			{
				return _MAX_SALARY;
			}
			set
			{
				_MAX_SALARY = value;
			}
		}
	
        #region EMPLOYEES 
        private EntityCollection _EMPLOYEES;
		///<summary>
		/// Related table EMPLOYEES as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(EMPLOYEES),"EMPLOYEES")]
        public EntityCollection EMPLOYEES
        {
            get
            {
                return _EMPLOYEES;
            }

            set
            {
                _EMPLOYEES = value;
            }
        }
        private EMPLOYEES _EMPLOYEES_;
		///<summary>
		/// Related table EMPLOYEES as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public EMPLOYEES EMPLOYEES_
        {
            get
            {
                return _EMPLOYEES_;
            }

            set
            {
                _EMPLOYEES_ = value;
            }
        }
        #endregion
	
        #region JOB_HISTORY 
        private EntityCollection _JOB_HISTORY;
		///<summary>
		/// Related table JOB_HISTORY as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(JOB_HISTORY),"JOB_HISTORY")]
        public EntityCollection JOB_HISTORY
        {
            get
            {
                return _JOB_HISTORY;
            }

            set
            {
                _JOB_HISTORY = value;
            }
        }
        private JOB_HISTORY _JOB_HISTORY_;
		///<summary>
		/// Related table JOB_HISTORY as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public JOB_HISTORY JOB_HISTORY_
        {
            get
            {
                return _JOB_HISTORY_;
            }

            set
            {
                _JOB_HISTORY_ = value;
            }
        }
        #endregion
	    /// <summary>
	    /// Gets join for current entity and table.
	    /// </summary>
	    /// <param name="tableName">Table to join with entity.</param>
	    /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "EMPLOYEES", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".JOB_ID");
				right.Add(GetType().Name + ".JOB_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "JOB_HISTORY", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".JOB_ID");
				right.Add(GetType().Name + ".JOB_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			return null;
		}
	}
}


